package 每日一题;

import java.util.HashSet;

public class 找到小镇的法官 {
    public int findJudge(int n, int[][] trust) {
        int res = -1;
        HashSet<Integer> set = new HashSet<>();
        for (int i = 0; i < trust.length; i++) {
            set.add(trust[i][0]);
        }
        for (int i = 1; i <=n; i++) {
            if (!set.contains(i))
                res = i;
        }
        int num = 0;
        for (int i = 0; i < trust.length; i++) {
            if (trust[i][1]==res)
                num++;
        }
        return num==n-1?res:-1;
    }
}
